package com.hspedu.newData.dmsxl.树.二叉树路径;

import com.hspedu.newData.dmsxl.ds.TreeNode;

/**
 * @Author: yh
 * @description: 
 * @CreateTime: 2025-05-26 
 * @Version: 1.0
 */

//todo
public class LC1448统计二叉树中好节点的数目 {
    public int goodNodes(TreeNode root) {

        int res = dfs(root, Integer.MIN_VALUE);
        return res;
    }

    public int dfs(TreeNode root,int pathMax){
        if (root==null) return 0;

        int res = 0;

        if (root.val >= pathMax){
            res++;
            pathMax = root.val;
        }
        res += dfs(root.left,pathMax) + dfs(root.right,pathMax);
        return res;
    }
}
